package com.feiyangedu.time;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.temporal.TemporalAdjusters;

public class Calculate {
    public static void main(String[] args) {
        LocalDateTime ldt = LocalDateTime.now();
        System.out.println(ldt);

//        +5 days
        LocalDateTime ldt2 = ldt.plusDays(5);
        System.out.println(ldt2);

//        -2 hour
        LocalDateTime ldt3 = ldt.minusHours(2);
        System.out.println(ldt3);

//         当月第一天
        LocalDate firstDay = LocalDate.now().withDayOfMonth(1);
        LocalDate firstDay2 = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
        System.out.println(firstDay.equals(firstDay2));
        System.out.println(firstDay);

//        当月最后一天
        LocalDate lastDay = LocalDate.now().with(TemporalAdjusters.lastDayOfMonth());
        System.out.println(lastDay);

//        当月第一个星期日
        LocalDate firstSunday = LocalDate.now().with(TemporalAdjusters.firstInMonth(DayOfWeek.SUNDAY));
        System.out.println(firstSunday);

//        判断日期前后
        System.out.println(firstSunday.isBefore(firstDay));

//        日期差
        Period p = LocalDate.now().until(LocalDate.of(2000,1,1));
        System.out.println(p);

//        日期差 天数
        System.out.println(LocalDate.of(2050,1,1).toEpochDay() -LocalDate.now().toEpochDay());
    }
}
